package com.mt.roll.wms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.EquipmentBomDetailParam;
import com.mt.roll.wms.params.EquipmentBomDetailQueryParam;
import com.mt.roll.wms.service.EquipmentBomDetailService;
import com.mt.roll.wms.vo.EquipmentBomDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2021/1/4 10:06
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "equipment-bom-detail")
@Slf4j
@Api(value = "设备物料bom详情 管理", tags = "设备物料bom详情 管理", hidden = false)
public class EquipmentBomDetailController {
    @Autowired
    EquipmentBomDetailService equipmentBomDetailService;

    /**
     * 新建物料bom-detail
     * */
    @PostMapping(value = "create")
    @ApiOperation(value = "新建物料bom")
    private R<Boolean> create(@Validated({Default.class}) @RequestBody EquipmentBomDetailParam equipmentBomDetailParam) {
        return equipmentBomDetailService.create(equipmentBomDetailParam);
    }

    @PostMapping(value = "findById")
    @ApiOperation(value = "依据物料bom详情 id查询")
    private R<EquipmentBomDetailVo> findById(@Validated({Default.class}) @RequestBody IdParam idParam) {
        return equipmentBomDetailService.findById(idParam);
    }

    /**
     * 更新物料bom
     * */
    @PostMapping(value = "update")
    @ApiOperation(value = "更新物料bom 依据ID 修改（传需要改的内容或者都传都行。）")
    private R<Boolean> update(@Validated({Default.class}) @RequestBody EquipmentBomDetailParam equipmentBomDetailParam) {
        return equipmentBomDetailService.update(equipmentBomDetailParam);
    }

    /**
     * 删除物料bom
     * */
    @PostMapping(value = "delete")
    @ApiOperation(value = "删除物料bom （依据ID 删除）")
    private R<Boolean> delete(@Validated @RequestBody IdParam idParam) {
        return equipmentBomDetailService.delete(idParam);
    }

    /**
     * 查询物料bom
     * */
    @PostMapping(value = "findAllByEQBomIdWithPage")
    @ApiOperation(value = "查询所有Bom-detail 依据bom id(分页);;把 bomId 放入id 字段")
    private R<IPage<EquipmentBomDetailVo>> findAllByEQBomIdWithPage(@Validated({Default.class}) @RequestBody EquipmentBomDetailQueryParam equipmentBom) {

        return equipmentBomDetailService.findAllByEQBomId(equipmentBom);
    }


}
